package com.workflow.listener;

import com.oa.service.LeaveService;
import com.oa.service.ReimbursementService;
import com.oa.utils.MyWebUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @Author Str
 * @Date 2021/12/17 10:17
 * @Description :
 */
public class ReimbursementEndHandler implements ExecutionListener {
    private ReimbursementService reimbursementService;

    public ReimbursementEndHandler() {
        //{ps}将 service 的 Bean 装配上来。
        reimbursementService = MyWebUtils.getBean(ReimbursementService.class);
    }

    @Override
    public void notify(DelegateExecution exce)
            throws Exception {
        //{1}获取流程变量
        String isCancel = (String) exce.getVariable("isCancel");
        String _status = "已办结";  //默认值
        //{2}根据 cancel 变量设置状态
        //   {a}已取消  {b}已办结
        if ("true".equals(isCancel)) {
            _status = "已取消";
        }
        //{3}获取到流程的实例ID
        String procInstId = exce.getProcessInstanceId();
        //{4}更新流程的状态
        reimbursementService.updateStatusByInstanceId(procInstId, _status);
        //{5}更新办理人与任务ID为  --> null
        // 不用将taskId和办理人置空
//        reimbursementService.updateAssigneeAndTask(procInstId, null, null);
//        printMark("{Handler}更新办理人为空");
    }

    private void printMark(Object obj) {
        System.out.println("+--------------------------------------+");
        System.out.println(obj);
        System.out.println("+--------------------------------------+");
    }
}
